package br.fatec.ads.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.fatec.ads.dao.RedeSocialDAO;
import br.fatec.ads.exception.DataBaseException;
import br.fatec.ads.exception.RedeSocialException;
import br.fatec.ads.model.RedeSocial;

public class RedeSocialExcluir extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public RedeSocialExcluir() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(false);
		
		RedeSocial redeSocial = new RedeSocial();
		redeSocial.setIdRedeSocial(Integer.parseInt(request.getParameter("idRedeSocialExcluir")));
		redeSocial.setUsuario(session.getAttribute("usuarioDesc").toString());
		
		RedeSocialDAO redeSocialDAO = new RedeSocialDAO();
		try {
			redeSocialDAO.excluirRedeSocial(redeSocial);
			request.getRequestDispatcher("RedeSocialPesquisar?acao=SUCESSO_EXCLUIR").forward(request, response);
		} catch (RedeSocialException e) {
			request.getRequestDispatcher("RedeSocialPesquisar?acao=ERRO_EXCLUIR").forward(request, response);
			e.printStackTrace();
		} catch (DataBaseException e) {
			request.getRequestDispatcher("RedeSocialPesquisar?acao=ERRO_EXCLUIR").forward(request, response);
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
